'use strict';

const BaseService = require('./base');

class AdvantageService extends BaseService {
  get _model() {
    return 'Advantage';
  }

  async findOne({ id }) {
    const where = { id };
    return this._findOne({ where });
  }

  async create({ name }) {
    return this._create({
      name,
    });
  }

  async update({ name, id }) {
    const where = { id };
    const body = { name };
    return this._update({ body, where });
  }

  async destory(id) {
    const where = { id };
    return this._destory({ where });
  }

  async findList({ name, prop, sort, pageIndex, pageSize, createdAt }) {
    const where = this.formatWhere({ dim: { name }, range: { createdAt } });
    const order = this.formatOrder(prop, sort);
    return this._findList({ pageIndex, pageSize, where, order });
  }

  async findAll({ ids } = {}) {
    let where = {};
    if (ids) {
      where = this.formatWhere({ inOp: { id: ids } });
    }
    return this._findAll({ where });
  }
}

module.exports = AdvantageService;
